package com.zd.common.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class charSetFilter implements Filter {
    private String encoding="UTF-8";
    public void destroy() {
    }
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest re=(HttpServletRequest)req;
        HttpServletResponse rp=(HttpServletResponse)resp;
        re.setCharacterEncoding(encoding);
        rp.setContentType("text/html;charset="+encoding);
        chain.doFilter(req, resp);
    }
    public void init(FilterConfig config) throws ServletException {
        /*初始化web.xml中的配置*/
        encoding=config.getInitParameter("encoding");
    }

}
